<?php

/**
* 跨境电商商城系统
 * =============================================
 * Copy right 2016-2026 大连熠泽科技网络有限公司
 * ---------------------------------------------
 * 官方网址: http://www.yizehuitong.com
 * =============================================
 * @author : yizehuitong
 * @date : 2019.10
 * @version : v2.0
 */

namespace addons\NsCombopackage\api\controller;

use addons\NsCombopackage\data\service\Promotion;
use app\api\controller\BaseApi;
use data\service\Goods as GoodsService;

/**
 * 组合套餐控制器
 */
class ComboPackage extends BaseApi
{
	/**
	 * 组合套餐
	 */
	public function comboPackageGoodsQuery()
	{
		$title = '商品组合套餐列表';
		$combo_package = new Promotion();
		$goods_id = isset($this->params['goods_id']) ? $this->params['goods_id'] : 0;
		if (empty($goods_id)) {
			return $this->outMessage($title, null, -50, '无法获取商品信息');
		}
		$combo_package = $combo_package->getComboPackageGoodsArray($goods_id, $this->category_ids);
		if (empty($combo_package)) {
			return $this->outMessage($title, null, -10, '未获取到套餐信息');
		}
		
		return $this->outMessage($title, $combo_package);
	}
	
	/**
	 * 根据id查询组合套餐
	 */
	public function comboPackageById()
	{
        $title = '选择优惠套餐';

		$promotion = new Promotion();
		$combo_id = isset($this->params['combo_id']) ? $this->params['combo_id'] : 0;
		$curr_id = isset($this->params['curr_id']) ? $this->params['curr_id'] : "";
		$combo_package = $promotion->getComboPackageGoodsById($combo_id, $curr_id, $this->category_ids);
		
		$data = [
			'combo_package' => $combo_package,
			'combo_id' => $combo_id
		];
		return $this->outMessage($title, $data);
	}
	
	/**
	 * 弹出组合商品sku选择框
	 */
	public function comboPackageSelectSku()
	{
		$title = '组合商品规格';
		$goods = new GoodsService();
		$goods_id = isset($this->params['goods_id']) ? $this->params['goods_id'] : "";
		if (empty($goods_id)) {
			return $this->outMessage($title, '', -50, '无法获取商品信息');
		}
		$goods_detail = $goods->getGoodsDetail($goods_id);
		if (empty($goods_detail)) {
			return $this->outMessage($title, '', -10, '未获取到套餐信息');
		}
		return $this->outMessage($title, $goods_detail);
	}
	
}